package com.ruoyi.web.controller.parts;

import java.util.List;

import com.ruoyi.system.domain.SysTools;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysParts;
import com.ruoyi.system.service.ISysPartsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 零件管理Controller
 * 
 * @author ruoyi
 * @date 2021-10-31
 */
@RestController
@RequestMapping("/system/parts")
public class SysPartsController extends BaseController
{
    @Autowired
    private ISysPartsService sysPartsService;

    /**
     * 查询零件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:parts:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysParts sysParts)
    {
        startPage();
        List<SysParts> list = sysPartsService.selectSysPartsList(sysParts);
        return getDataTable(list);
    }

    /**
     * 导出零件管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:parts:export')")
    @Log(title = "零件管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysParts sysParts)
    {
        List<SysParts> list = sysPartsService.selectSysPartsList(sysParts);
        ExcelUtil<SysParts> util = new ExcelUtil<SysParts>(SysParts.class);
        return util.exportExcel(list, "零件管理数据");
    }

    /**
     * 获取零件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:parts:query')")
    @GetMapping(value = "/{partId}")
    public AjaxResult getInfo(@PathVariable("partId") String partId)
    {
        return AjaxResult.success(sysPartsService.selectSysPartsByPartId(partId));
    }

    /**
     * 新增零件管理
     */
    @PreAuthorize("@ss.hasPermi('system:parts:add')")
    @Log(title = "零件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysParts sysParts)
    {
        return toAjax(sysPartsService.insertSysParts(sysParts));
    }

    /**
     * 修改零件管理
     */
    @PreAuthorize("@ss.hasPermi('system:parts:edit')")
    @Log(title = "零件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysParts sysParts)
    {
        return toAjax(sysPartsService.updateSysParts(sysParts));
    }

    /**
     * 删除零件管理
     */
    @PreAuthorize("@ss.hasPermi('system:parts:remove')")
    @Log(title = "零件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partIds}")
    public AjaxResult remove(@PathVariable String[] partIds)
    {
        return toAjax(sysPartsService.deleteSysPartsByPartIds(partIds));
    }


    @GetMapping("/allparts")
    @ResponseBody
    public List<SysParts> getAllparts(SysParts sysParts ){
        return sysPartsService.selectSysPartsList(sysParts);

    }


}
